/*
 * To change this license header, choose License Headers in Project Properties. To change this
 * template file, choose Tools | Templates and open the template in the editor.
 */
package chalmers.game.subterranean.util;

/**
 * 
 * @author TH
 */
public class BlockType {

  public final Dig dig;
  public final Action action;
  public final Resource resource;
  public final Nothing nothing;

  public BlockType(Dig dig) {
    this.dig = dig;
    this.action = Action.NULL;
    this.resource = Resource.NULL;
    this.nothing = Nothing.NULL;
    checkValid();
  }

  public BlockType(Action action) {
    this.dig = Dig.NULL;
    this.action = action;
    this.resource = Resource.NULL;
    this.nothing = Nothing.NULL;
    checkValid();
  }

  public BlockType(Resource resource) {
    this.dig = Dig.NULL;
    this.action = Action.NULL;
    this.nothing = Nothing.NULL;
    this.resource = resource;
    checkValid();
  }

  public BlockType(Nothing nothing) {
    this.dig = Dig.NULL;
    this.action = Action.NULL;
    this.resource = Resource.NULL;
    this.nothing = nothing;
    checkValid();
  }

  @Override
  public boolean equals(Object obj) {
    BlockType otherBT;
    if (obj.getClass().equals(this.getClass())) {
      otherBT = (BlockType) obj;
    } else {
      return false;
    }

    return otherBT.action.equals(action) & otherBT.dig.equals(dig)
        & otherBT.resource.equals(resource) & otherBT.nothing.equals(nothing);
  }

  private void checkValid() {
    if (action == null | dig == null | resource == null | nothing == null) {
      throw new IllegalInstantiationException(
          "You can't make an instance of BlockType without specifying what type it shall be.");
    }
  }

  private static class IllegalInstantiationException extends RuntimeException {
    public IllegalInstantiationException(String msg) {
      super(msg);
    }
  }

  public enum Dig {
    DIRT, STONE, AIR, NOTHING, NULL
  }
  public enum Action {
    LADDER, TELEPORT, NOTHING, SHOP, NULL
  }
  public enum Resource {
    IRON, COAL, DIAMOND, NULL
  }
  public enum Nothing {
    NULL
  }
}
